SQL in 24 Hours, Sams Teach Yourself by Stephens Ryan & Jones Arie D. & Plew Ron
Author:Stephens, Ryan & Jones, Arie D. & Plew, Ron [Stephens, Ryan]
Language: eng
Format: azw3
Publisher: Pearson Education
Published: 2015-12-10T16:00:00+00:00
Subqueries with the SELECT Statement
Subqueries are most frequently used with the SELECT statement; although you can use them within a data manipulation statement as well. The subquery when employed with the SELECT statement retrieves data for the main query to use.
The basic syntax follows:
Click here to view code image
SELECT COLUMN_NAME [, COLUMN_NAME ]
FROM TABLE1 [, TABLE2 ]
WHERE COLUMN_NAME OPERATOR
(SELECT COLUMN_NAME [, COLUMN_NAME ]
FROM TABLE1 [, TABLE2 ]
[ WHERE ])
Following is an example:
Click here to view code image
SELECT E.EMPLOYEEID,E.LASTNAME,
A.AIRPORTNAME, E.SALARY
FROM EMPLOYEES E
INNER JOIN AIRPORTS A
ON E.AIRPORTID = A.AIRPORTID
WHERE E.SALARY=
( SELECT SALARY
FROM EMPLOYEES
WHERE EMPLOYEEID=3908);
The preceding SQL statement returns the employee identification, last name, and salary for all employees who have a salary equal to that of the employee with the identification 3908. In this case, you do not necessarily know (or care) what the exact pay rate is for this particular employee; you care only about the pay rate for the purpose of getting a list of employees who bring home pay equal to the employee specified in the subquery.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Access | Data Mining |
Data Modeling & Design | Data Processing |
Data Warehousing | MySQL |
Oracle | Other Databases |
Relational Databases | SQL |
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8296)
Azure Data and AI Architect Handbook by Olivier Mertens & Breght Van Baelen(6720)
Building Statistical Models in Python by Huy Hoang Nguyen & Paul N Adams & Stuart J Miller(6699)
Serverless Machine Learning with Amazon Redshift ML by Debu Panda & Phil Bates & Bhanu Pittampally & Sumeet Joshi(6570)
Data Wrangling on AWS by Navnit Shukla | Sankar M | Sam Palani(6354)
Driving Data Quality with Data Contracts by Andrew Jones(6304)
Machine Learning Model Serving Patterns and Best Practices by Md Johirul Islam(6071)
Learning SQL by Alan Beaulieu(5994)
Weapons of Math Destruction by Cathy O'Neil(5778)
Big Data Analysis with Python by Ivan Marin(5354)
Data Engineering with dbt by Roberto Zagni(4351)
Solidity Programming Essentials by Ritesh Modi(3999)
Time Series Analysis with Python Cookbook by Tarek A. Atwan(3857)
Pandas Cookbook by Theodore Petrou(3569)
Blockchain Basics by Daniel Drescher(3292)
Hands-On Machine Learning for Algorithmic Trading by Stefan Jansen(2905)
Feature Store for Machine Learning by Jayanth Kumar M J(2812)
Learn T-SQL Querying by Pam Lahoud & Pedro Lopes(2794)
Mastering Python for Finance by Unknown(2744)
